import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { JCronValidator } from "/@/components/Form"
import { listTaskBean } from "./job.api"

export const columns: BasicColumn[] = [
  {
    title: "任务名称",
    dataIndex: "jobName",
    width: 130,
  },
  {
    title: "任务组名",
    dataIndex: "jobGroup",
    width: 100,
    customRender: ({ text }) => {
      return render.renderDict(text, "sys_job_group")
    },
  },
  {
    title: "调用目标",
    dataIndex: "invokeTarget",
    width: 200,
    align: "left",
  },

  {
    title: "Cron表达式",
    dataIndex: "cronExpression",
    width: 150,
  },
  // {
  //   title: '参数',
  //   dataIndex: 'parameter',
  //   width: 200,
  // },
  // {
  //   title: '描述',
  //   dataIndex: 'remark',
  //   width: 100,
  // },
  {
    title: "状态",
    dataIndex: "status",
    width: 60,
    customRender: ({ text }) => {
      const color = text == "1" ? "red" : text == "0" ? "green" : "gray"
      return render.renderTag(render.renderDict(text, "quartz_status"), color)
    },
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: "jobName",
    label: "任务名称",
    component: "Input",
    colProps: { span: 8 },
  },
  {
    field: "status",
    label: "任务状态",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "quartz_status",
      stringToNumber: true,
    },
    colProps: { span: 8 },
  },
]

export const formSchema: FormSchema[] = [
  {
    field: "id",
    label: "id",
    component: "Input",
    show: false,
  },
  {
    field: "jobName",
    label: "任务名称",
    component: "Input",
    required: true,
  },
  {
    label: "任务分组",
    field: "jobGroup",
    component: "JDictSelectTag",
    required: true,
    componentProps: {
      dictType: "sys_job_group",
      placeholder: "请选择任务分组",
      // stringToNumber: true
    },
  },
  {
    label: "调用目标",
    field: "invokeTarget",
    component: 'ApiSelect',
    componentProps: {
      api: listTaskBean,
      showSearch: true,
      allowClear: true,
      labelField: 'labal',
      valueField: 'key',
    },
    required: true,
  },
  {
    field: "cronExpression",
    label: "Cron表达式",
    component: "JEasyCron",
    defaultValue: "* * * * * ? *",
    rules: [{ required: true, message: "请输入Cron表达式" }, { validator: JCronValidator }],
  },
  {
    field: "targetParams",
    label: "参数",
    component: "JAddInput",
    helpMessage: "键值对形式填写",
  },
  {
    field: "status",
    label: "状态",
    component: "JDictSelectTag",
    defaultValue: "0",
    componentProps: {
      dictType: "quartz_status",
      type: "radio",
      // stringToNumber: true,
    },
  },
  {
    field: "remark",
    label: "描述",
    component: "InputTextArea",
  },
]
